module Shape {
	export class AdvanceArc extends egret.DisplayObjectContainer {

		private _shape: egret.Shape;
		private _girl:egret.Bitmap;

		constructor() {
			super();
			this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
		}

		private onAddToStage(event: egret.Event) {
			//添加图形
			this._shape=new egret.Shape();
			this._shape.x = this.stage.stageWidth / 2;
			this._shape.y = this.stage.stageHeight / 2;
			this.addChild(this._shape);
			//加载图片
			var loader: egret.ImageLoader = new egret.ImageLoader();
			loader.addEventListener(egret.Event.COMPLETE, function (e: egret.Event) {
				var bitmapData: egret.BitmapData = loader.data;
				this._girl = new egret.Bitmap(bitmapData);
				this.addChild(this._girl);
				//this._girl.width = 228;
				//this._girl.height = 380;
				this._girl.x = this._shape.x - this._girl.width / 2;
				this._girl.y =  this._shape.y - this._girl.height / 2;
				this._girl.mask =  this._shape;
			}, this);
			loader.load("resource/hero.png");
			this.changeGraphics();
		}

		//轻触修改属性
		private changeGraphics(): void {
			var shape: egret.Shape = this._shape;

			var angle: number = 0;
			var i: number = 1;
			egret.startTick(function(timeStamp:number):boolean{
				angle++;
				if(angle>=360){
					angle%=360;
					i*=-1;
				}
				changeGraphics(angle);
				return false;
			},this);

			function changeGraphics(angle: number): void {
				shape.graphics.clear();

				shape.graphics.beginFill(0x00ffff, 1);
				shape.graphics.moveTo(0, 0);
				shape.graphics.lineTo(200, 0);
				shape.graphics.drawArc(0, 0, 200, 0, angle * Math.PI / 180, i == -1);
				shape.graphics.lineTo(0, 0);
				shape.graphics.endFill();
			}
		}
	}
}